<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
</head>
<body layadmin-themealias="default">

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body" pad15="">
                    <div class="layui-form" wid100="" lay-filter="">
                        <input type="hidden" name="id" value="{$expert_plan.id}">
                        <div class="layui-form-item">
                            <label class="layui-form-label">标题</label>
                            <div class="layui-input-inline" style="width:350px;">
                                <input type="text" name="title" value="{$expert_plan.title}" placeholder="请输入标题" class="layui-input" lay-verify="required" maxlength="255">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">选择专家</label>
                            <div class="layui-input-inline">
                                <select name="expert_id" lay-verify="required">
                                    <option value=""></option>
                                    {volist name="expert_list" id="vo"}
                                    <option value="{$vo.id}" {$expert_plan.expert_id==$vo.id?'selected':''}>{$vo.nick_name}（ID:{$vo.id}）</option>
                                    {/volist}
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">联赛分类</label>
                            <div class="layui-input-inline">
                                <select id="sportId" name="sport_id" lay-filter="sport_id" lay-verify="required">
                                    <option value=""></option>
                                    <option value="1" {$expert_plan.sport_id==1?'selected':''}>足球</option>
                                    <option value="2" {$expert_plan.sport_id==2?'selected':''}>篮球</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item sport">
                            <label class="layui-form-label">赛事选择</label>
                            <div class="layui-input-inline" style="width: 400px;">
                                <select name="match_id" id="matchId" data-matchid="{$expert_plan.match_id}" lay-filter="match_id" disabled="disabled" lay-verify="required" lay-search="">
                                    <option value="">请输入赛事名称</option>
                                </select>
                            </div>
                        </div>


                        <div class="layui-form-item">
                            <label class="layui-form-label">玩法类型</label>
                            <div class="layui-input-inline">
                                <select name="play_type" id="playType" lay-filter="play_type" data-default="{$expert_plan.play_type}" data-sport-id="{$expert_plan.sport_id}" lay-verify="required">
                                    <option value="">请选择</option>
                                </select>
                            </div>
                        </div>

                        <div id="playOddsHtml"></div>

                        <!--篮球-->
                        <!--欧指-->
                        <script id="playBasketOdds1" type="text/html">
                            <div class="layui-form-item">
                                <label class="layui-form-label">主(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[1]" value="{$expert_plan.play_type==1&&$expert_plan.sport_id==2?$expert_plan.main_one_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">客(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[3]" value="{$expert_plan.play_type==1&&$expert_plan.sport_id==2?$expert_plan.main_three_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">专家预测</label>
                                <div class="layui-input-inline">
                                    <select name="expert_play_win" lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="1" {$expert_plan.play_type==1&&$expert_plan.main_one_recommend&&$expert_plan.sport_id==2?'selected':''}>主</option>
                                        <option value="3" {$expert_plan.play_type==1&&$expert_plan.main_three_recommend&&$expert_plan.sport_id==2?'selected':''}>客</option>
                                    </select>
                                </div>
                            </div>
                        </script>

                        <!--让分-->
                        <script id="playBasketOdds2" type="text/html">
                            <div class="layui-form-item">
                                <label class="layui-form-label">主(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[1]" value="{$expert_plan.play_type==2&&$expert_plan.sport_id==2?$expert_plan.main_one_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盘口</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[2]" value="{$expert_plan.play_type==2&&$expert_plan.sport_id==2?$expert_plan.main_two_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">客(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[3]" value="{$expert_plan.play_type==2&&$expert_plan.sport_id==2?$expert_plan.main_three_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">专家预测</label>
                                <div class="layui-input-inline">
                                    <select name="expert_play_win" lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="1" {$expert_plan.play_type==2&&$expert_plan.main_one_recommend&&$expert_plan.sport_id==2?'selected':''}>主</option>
                                        <option value="3" {$expert_plan.play_type==2&&$expert_plan.main_three_recommend&&$expert_plan.sport_id==2?'selected':''}>客</option>
                                    </select>
                                </div>
                            </div>
                        </script>
                        <!--总分-->
                        <script id="playBasketOdds3" type="text/html">
                            <div class="layui-form-item">
                                <label class="layui-form-label">主(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[1]" value="{$expert_plan.play_type==3&&$expert_plan.sport_id==2?$expert_plan.main_one_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盘口</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[2]" value="{$expert_plan.play_type==3&&$expert_plan.sport_id==2?$expert_plan.main_two_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">客(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[3]" value="{$expert_plan.play_type==3&&$expert_plan.sport_id==2?$expert_plan.main_three_odds:''}" placeholder="请输入让球数" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <!--expert_play_win[3],数组3是玩法类型-->
                            <div class="layui-form-item">
                                <label class="layui-form-label">专家预测</label>
                                <div class="layui-input-inline">
                                    <select name="expert_play_win" lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="1" {$expert_plan.play_type==3&&$expert_plan.main_one_recommend==1&&$expert_plan.sport_id==2?'selected':''}>主</option>
                                        <option value="3" {$expert_plan.play_type==3&&$expert_plan.main_three_recommend==3&&$expert_plan.sport_id==2?'selected':''}>客</option>
                                    </select>
                                </div>
                            </div>
                        </script>


                        <!--足球-->
                        <!--欧指-->
                        <script id="playOdds1" type="text/html">
                            <div class="layui-form-item">
                                <label class="layui-form-label">胜(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[1]" value="{$expert_plan.play_type==1&&$expert_plan.sport_id==1?$expert_plan.main_one_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">平(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[2]" value="{$expert_plan.play_type==1&&$expert_plan.sport_id==1?$expert_plan.main_two_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">负(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[3]" value="{$expert_plan.play_type==1&&$expert_plan.sport_id==1?$expert_plan.main_three_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>

                            <div class="layui-form-item">
                                <label class="layui-form-label">专家预测</label>
                                <div class="layui-input-inline">
                                    <select name="expert_play_win" lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="1" {$expert_plan.play_type==1&&$expert_plan.main_one_recommend&&$expert_plan.sport_id==1?'selected':''}>胜</option>
                                        <option value="2" {$expert_plan.play_type==1&&$expert_plan.main_two_recommend&&$expert_plan.sport_id==1?'selected':''}>平</option>
                                        <option value="3" {$expert_plan.play_type==1&&$expert_plan.main_three_recommend&&$expert_plan.sport_id==1?'selected':''}>负</option>
                                    </select>
                                </div>
                            </div>
                        </script>

                        <!--让球-->
                        <script id="playOdds2" type="text/html">
                            <div class="layui-form-item">
                                <label class="layui-form-label">主(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[1]" value="{$expert_plan.play_type==2&&$expert_plan.sport_id==1?$expert_plan.main_one_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盘口</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[2]" value="{$expert_plan.play_type==2&&$expert_plan.sport_id==1?$expert_plan.main_two_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">客(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[3]" value="{$expert_plan.play_type==2&&$expert_plan.sport_id==1?$expert_plan.main_three_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">专家预测</label>
                                <div class="layui-input-inline">
                                    <select name="expert_play_win" lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="1" {$expert_plan.play_type==2&&$expert_plan.main_one_recommend&&$expert_plan.sport_id==1?'selected':''}>主</option>
                                        <option value="3" {$expert_plan.play_type==2&&$expert_plan.main_three_recommend&&$expert_plan.sport_id==1?'selected':''}>客</option>
                                    </select>
                                </div>
                            </div>
                        </script>
                        <!--大小-->
                        <script id="playOdds3" type="text/html">
                            <div class="layui-form-item">
                                <label class="layui-form-label">大(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[1]" value="{$expert_plan.play_type==3&&$expert_plan.sport_id==1?$expert_plan.main_one_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">盘口</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[2]" value="{$expert_plan.play_type==3&&$expert_plan.sport_id==1?$expert_plan.main_two_odds:''}" placeholder="请输入赔率" class="layui-input" lay-verify="required">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label class="layui-form-label">小(赔率)</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="expert_play[3]" value="{$expert_plan.play_type==3&&$expert_plan.sport_id==1?$expert_plan.main_three_odds:''}" placeholder="请输入让球数" class="layui-input" lay-verify="required|number">
                                </div>
                            </div>
                            <!--expert_play_win[3],数组3是玩法类型-->
                            <div class="layui-form-item">
                                <label class="layui-form-label">专家预测</label>
                                <div class="layui-input-inline">
                                    <select name="expert_play_win" lay-verify="required">
                                        <option value="">请选择</option>
                                        <option value="1" {$expert_plan.play_type==3&&$expert_plan.main_one_recommend&&$expert_plan.sport_id==1?'selected':''}>大</option>
                                        <option value="3" {$expert_plan.play_type==3&&$expert_plan.main_three_recommend&&$expert_plan.sport_id==1?'selected':''}>小</option>
                                    </select>
                                </div>
                            </div>
                        </script>


                        <div class="layui-form-item">
                            <label class="layui-form-label">价格单位</label>
                            <div class="layui-input-inline">
                                <select name="fee_type" lay-filter="fee_type" lay-verify="required">
                                    <option value="">请选择</option>
                                    <option value="0" {$expert_plan.fee_type==0?'selected':''}>免费</option>
                                    <option value="1" {$expert_plan.fee_type==1?'selected':''}>钻石</option>
                                    <option value="2" {$expert_plan.fee_type==2?'selected':''}>宝石</option>
                                </select>
                            </div>
                        </div>

                        <div class="layui-form-item" id="feePay" {if $expert_plan.fee_type==0}style="display:none"{/if}>
                            <label class="layui-form-label">价格</label>
                            <div class="layui-input-inline">
                                <input type="text" name="fee_pay" value="{$expert_plan.fee_pay}" placeholder="请输入正整数" class="layui-input" lay-verify="required|number" onkeyup="input_num(this)">
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <label class="layui-form-label">分析内容</label>
                            <div class="layui-input-block">
                                <textarea class="layui-textarea" name="content" placeholder="请输入分析内容" lay-verify="required">{$expert_plan.content}</textarea>
                            </div>
                        </div>

                        <div class="layui-form-item">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="expert-plan-edit">确认保存</button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/assets/cos-js-sdk-v5/cos-js-sdk-v5.min.js"></script>
<script src="/assets/ue/third-party/jquery-1.10.2.js"></script>
<script>

    var laytpl = null;
    var form = null;

    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
        , version: "{:config('other.ui_version')}"
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(["index", "expert", "laytpl", "admin", "element"], function () {
        var $ = layui.$
            , admin = layui.admin;

        laytpl = layui.laytpl;
        form = layui.form;

        //赛事选择监听
        form.on('select(sport_id)', function (data) {
            selectMatchInfo()
        });

        selectMatchInfo();

        // 赛事选择
        function selectMatchInfo() {
            var sport_id = $('#sportId option:selected').val();
            let select = $("#matchId");
            var selected_id = $("#matchId").data('matchid');
            // 玩法类型选择
            setPlaySelect(sport_id);

            $('#matchId').empty();
            if (sport_id > 0) {
                layer.load();
                $.ajax({
                    url: '{:url("expert/get_match")}',
                    type: 'get',
                    data: {
                        sport_id: sport_id,
                        edit_matchid:selected_id
                    },
                    dataType: 'json',
                    success: function (result) {
                        layer.closeAll('loading');
                        $("#matchId").removeAttr("disabled");
                        select.append(new Option("请输入赛事名称", ""));
                        $.each(result.data, function (index, item) {
                            var se_title = item.home + '-' + item.away + '(比赛时间：' + item.match_time_str + ')';

                            var is_selected = selected_id == item.match_id ? true : false;
                            select.append(new Option(se_title, item.match_id, 0, is_selected));
                        });
                        form.render("select");
                    },
                    complete:function(){
                        layer.closeAll('loading');
                    }

                });
            } else {
                select.append(new Option("- - -", ""));
                $('#matchId').attr("disabled", "disabled");
                form.render("select");
            }
        }


        // 设置玩法名称
        function setPlaySelect(sport_id) {
            let select = $('#playType');
            let default_val = select.data('default');
            let default_sport_id = select.data('sportId');
            // 玩法类型置空
            select.empty();

            // 玩法赔率输入框区域置空
            setFromBody()

            select.append(new Option("请选择", ""));
            if (sport_id == 1) {
                // 足球
                select.append(new Option('欧指', 1, 0, (default_val == 1 && default_sport_id == 1 ? true : false)));
                select.append(new Option('让球', 2, 0, (default_val == 2 && default_sport_id == 1 ? true : false)));
                select.append(new Option('大小', 3, 0, (default_val == 3 && default_sport_id == 1 ? true : false)));
            } else {
                // 篮球
                select.append(new Option('欧指', 1, 0, (default_val == 1 && default_sport_id == 2 ? true : false)));
                select.append(new Option('让分', 2, 0, (default_val == 2 && default_sport_id == 2 ? true : false)));
                select.append(new Option('总分', 3, 0, (default_val == 3 && default_sport_id == 2 ? true : false)));
            }
            form.render("select");
            // 玩法赔率输入框区域置空
            setFromBody()
        }


        // 类型选择
        form.on("select(play_type)", function (data) {
            setFromBody();
        });

        function setFromBody() {
            let play_type_val = $('#playType option:selected').val();
            let sport_id = $('#sportId').val();
            var html = '';
            if (sport_id == 1) {
                // 足球
                html = $('#playOdds' + play_type_val).html();
            } else {
                // 篮球
                html = $('#playBasketOdds' + play_type_val).html();
            }

            if (!play_type_val) {
                html = '';
            }

            laytpl(html).render({}, function (html) {
                $("#playOddsHtml").html(html);
                form.render();
            });
        }

        // 付费选择
        form.on("select(fee_type)", function (data) {
            var type_val = data.value;
            if (type_val > 0) {
                $('#feePay').show();
                $('#feePay').val(0);
            } else {
                $('#feePay').hide();
            }
        });
    });

    function input_num(obj){
        obj.value = obj.value.replace(/[^\d.]/g,"");
        obj.value = obj.value.replace(/^\./g,"");
        obj.value = obj.value.replace(/\.{2,}/g,".");
        obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');

        if(obj.value.indexOf(".")> 0  && obj.value.indexOf("0")>2){
            obj.value= parseFloat(obj.value);
        }
        if(obj.value.indexOf(".")> 0  && obj.value.lastIndexOf("0")>2){
            obj.value= parseFloat(obj.value);
        }
        if (obj.value.indexOf(".") <= 0 && obj.value != "") {
            obj.value = parseFloat(obj.value);
        }
    }

</script>
</body>
</html>
